<?php

namespace App\Jobs;
use App\Jobs\SendEmail;
use Illuminate\Support\Facades\Config;
use Overtrue\EasySms\EasySms;
use Illuminate\Support\Facades\Mail;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
use Log;

class SendEmail extends Job {
	/**
	 * Create a new job instance.
	 *
	 * @return void
	 */
	protected $view,$data,$to,$subject;
	public function __construct($view,$data,$to,$subject) {
		//
        $this->view = $view;
        $this->data = $data;
        $this->to = $to;
        $this->subject = $subject;
	}

	/**
	 * Execute the job.
	 *
	 * @return void
	 */
	public function handle() {
	    $to = $this->to;
	    $subject = $this->subject;
		try
		{
            Mail::send($this->view, ['data'=>$this->data], function ($message) use ($to, $subject) {
                $message->to($to,'我')->subject($subject);
            });
            Log::info($to);
		} catch (NoGatewayAvailableException $e) {
            Log::info($e);
		}
	}
}
